<template>
    <div class="page-container">
        <div>
            <div class="operation-container">
                <el-button type="primary" @click="onPrint">打印</el-button>
            </div>
            <div id="deviceDispatchPrint" class="print-container">
                <div class="print-title">仪器采购申请单</div>
                <table class="table-class" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <td class="print-label">采购部门</td>
                        <td class="print-input-content2">
                            {{ form.departmentName }}
                        </td>
                        <td class="print-label">采购项目</td>
                        <td class="print-input-content2">
                            {{ form.projectName }}
                        </td>
                    </tr>
                    <tr>
                        <td class="print-label">拟投入的项目概况</td>
                        <td class="print-input-content" colspan="3">
                            {{ form.projectProfile }}
                        </td>
                    </tr>
                    <tr>
                        <td class="print-label">仪器名称</td>
                        <td class="print-input-content2">
                            {{ form.deviceName }}
                        </td>
                        <td class="print-label">仪器型号</td>
                        <td class="print-input-content2">
                            {{ form.deviceModel }}
                        </td>
                    </tr>
                    <tr>
                        <td class="print-label">采购类型</td>
                        <td class="print-input-content2">
                            {{ form.applyType }}
                        </td>
                        <td class="print-label">采购数量</td>
                        <td class="print-input-content2">
                            {{ form.applyNum }}
                        </td>
                    </tr>
                    <tr>
                        <td class="print-label">备注</td>
                        <td class="print-input-content" colspan="3">
                            {{ form.remark }}
                        </td>
                    </tr>
                    <tr>
                        <td class="print-label-line" colspan="4">审批信息</td>
                    </tr>
                    <tr>
                        <td class="print-table-line" colspan="4">
                            <PrintFlowHistoryCpt :taskId="id"></PrintFlowHistoryCpt>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
    </div>
</template>
<script>
import { ref, toRefs, reactive, onMounted } from 'vue'
import { ElNotification } from 'element-plus'
import http from '@/http.js'
import printJS from 'print-js'
import formatUtil from '@/utils/format.js'
import PrintFlowHistoryCpt from '../components/PrintFlowHistoryCpt.vue'

export default {
    props: {
        id: {
            type: String,
            default: ''
        }
    },
    components: {
        PrintFlowHistoryCpt
    },
    setup(props, ctx) {
        const state = reactive({
            form: {
                id: '',
                departmentId: '',
                departmentCode: '',
                departmentName: '',
                projectId: '',
                projectCode: '',
                projectName: '',
                projectProfile: '',
                applyType: 0,
                deviceName: '',
                deviceModel: '',
                applyNum: '',
                remark: '',
                processData: []
            },
            applyTypeOption: [
                {
                    label: '采购',
                    value: 0
                },
                {
                    label: '租赁',
                    value: 1
                }
            ],
            flowList: []
        })

        const loadDetail = () => {
            http.fetchForm({
                url: '/yunying/devicePurchase/findById',
                method: 'get',
                data: {
                    id: props.id
                }
            }).then((res) => {
                state.form = res.data
            })
        }

        const onPrint = () => {
            printJS({
                printable: 'deviceDispatchPrint',
                type: 'html',
                targetStyles: ['*'],
                style: '@page{margin-top: 1mm;margin-bottom: 1mm;}'
            })
        }

        onMounted(() => {
            loadDetail()
        })

        return {
            formatUtil,
            ...toRefs(state),
            onPrint
        }
    }
}
</script>
<style scoped>
@import '@/assets/css/print.css';
</style>
